package com.software.sqlite.utils;


import cn.hutool.core.text.UnicodeUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class HttpUtils {
    public static void main(String[] args) {
        requestToken();
    }

    public static String requestToken() {
        try {
            String url = "http://asmovie.ainetv.cn/freighter.php/V1/Auth/login";

            String AuthKey="KY5scEDu0Q6gPkhYm0AKuh0atEZs0Pgv";
            String AppKey="U5oOkHYvcNDnyJc1";
            HttpRequest request = HttpUtil.createPost(url);
//            request.header("token", "111111");
            Map<String, String> param = new HashMap();
            param.put("AuthKey", AuthKey);
            param.put("AppKey", AppKey);
            String body = JSON.toJSONString(param);
            request.body(body);
            HttpResponse execute = request.execute();
            if (!execute.isOk()) {
                log.error("请求token失败,body={},execute={}", execute.body(), execute);
                throw new RuntimeException(execute.body());
            }
            String res = UnicodeUtil.toString(execute.body());
            System.out.println(res);
            return res;
        } catch (Exception e) {
            log.error("requestToken失败,msg={}", e.getMessage());
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }

    @Data
    public class AuthTokenResResult {

        private int code;

        private String msg;

        private AuthToken data;

        private long count;
    }

    @Data
    public class AuthToken {

        private String token;

        private long expireAt;
    }
}
